//
//  InterviewController.m
//  APJ HRadar
//
//  Created by Luna Gao on 14-4-1.
//  Copyright (c) 2014年 APJ. All rights reserved.
//

#import "InterviewController.h"
#import "HRStore.h"
#import "StaffInterviewCell.h"
#import "Interview.h"

@interface InterviewController ()

@end

@implementation InterviewController
{
    NSArray *datas;
}

- (id)initWithStaffId:(int)staffId
{
    self = [super init];
    
    if (self) {
        datas = [[HRStore sharedStore] interviewOfStaff:staffId];
    }
    
    return self;
}

- (id)init
{
    [NSException raise:@"Interview init error" format:@"please call initWithStaffId."];
    return nil;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    StaffInterviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"interview"];
    if(cell==nil){
        cell = [[[NSBundle mainBundle]loadNibNamed:@"StaffInterviewCell" owner:self options:nil] lastObject];
    }
    
    Interview *item = [datas objectAtIndex:indexPath.row];
    cell.exam1.text = [NSString stringWithFormat:@"%d", item.exam1];
    cell.exam2.text = [NSString stringWithFormat:@"%d", item.exam2];
    cell.exam3.text = [NSString stringWithFormat:@"%d", item.exam3];
    cell.interviewer.text = item.interviewer;
    cell.status.text = item.interviewStatus;
    cell.position.text = item.position;
    cell.comments.text = item.comments;
    
    NSDate *time = [NSDate dateWithTimeIntervalSince1970:item.interviewTime];
    NSDateFormatter *formate = [[NSDateFormatter alloc] init];
    formate.dateFormat = @"dd-MMM-YYYY";
    cell.time.text = [NSString stringWithFormat:@"%@", [formate stringFromDate:time]];
    
    cell.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 173.0;
}

@end
